package com.easy.core.dbHandle;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;

/**
 * <p>Description: </p>
 * <p>CreateDate:@2013-8-23</p>
 * @author zhangj
 */
public interface BasicService<T, PK extends Serializable> {

	T findById(final PK id);
	
	<K> Object findById(final Class<K> clazz, final PK id);
	
	List<T> findAll();
	
	<K> List<K> findAll(final Class<K> clazz);
	
	List<T> findByCriteria(final DetachedCriteria dc);
	
	List<T> findTopByCriteria(final DetachedCriteria dc, final int num);
	
	Long findCountByCriteria(final DetachedCriteria dc);
	
	PaginationSupport<T> findPageByCriteria(final DetachedCriteria dc, final int pageSize, final int startIndex, final List<Order> orderList);
	
	PaginationSupport<T> findPageByCriteria(final DetachedCriteria dc, final int pageSize, final int startIndex, final Order order);
	
	List<?> findByHQL(final String hql, final Object... params);
	
	PK save(final T object);
	
	void update(final T object);
	
	void delete(final T object);
	
	void delete(final PK id);
	
	Session getCurrentSession(boolean allowCreate);
	
	SessionFactory getSessionFactory();
	
}
